﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using DLTN.Entities;
using DLTN.Data;

public partial class GioiThieu_Controls_ControlGioiThieuContent : System.Web.UI.UserControl
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            HienThiGioiThieu();
        }
    }

    private void HienThiGioiThieu()
    {
        string strHTML = "";
        int TotalRows = 0;
        string WhereClause = "1=1";

        //// Get ChuyenMuc
        WhereClause += " and TrangThai = 1 and IdSubChuyenMuc in (select Id from SubChuyenMuc where TenSubChuyenMuc like N'%"+ Common.GioiThieu +"%')";
        TList<ChuyenMuc> TList_ChuyenMuc = DataRepository.ChuyenMucProvider.GetPaged(WhereClause, "NgayCapNhat DESC", 0, 1, out TotalRows);

        // Hiển thị lên trình duyệt
        if (TList_ChuyenMuc.Count > 0)
        {
            strHTML += "<div style=\"width: 630px;min-height:350px;height: auto;padding-bottom: 20px;\">";
            strHTML += "<img class=\"radius\" src=\"Upload/ChuyenMuc/" + TList_ChuyenMuc[0].AnhDaiDien + "\" width=\"630px\" height=\"300px\" border=\"0\"/>";
            strHTML += "<div style=\"width: 630px;min-height: 50px;height: auto;margin-bottom:10px;word-wrap:break-word;font-family: Arial, Helvetica, sans-serif;font-size: 13px;color:#696969;padding-top:10px;text-align:justify\">"+ TList_ChuyenMuc[0].TomTat + "</div>";
            strHTML += "<div style=\"width:71px; height: 17px; background:url('Images/dltn/seeMoreBg.png') no-repeat;float:right;\">";
            strHTML += "<a href=\"ChuyenMuc/" + TList_ChuyenMuc[0].Id + "/" + TList_ChuyenMuc[0].IdSubChuyenMuc + "/" + GetTieuDe(TList_ChuyenMuc[0].TieuDe) + ".aspx\" style=\"text-decoration:none; font-size:12px; padding-left:10px;padding-top:2px;color:#fff;\">Xem tiếp</a></div>";
            strHTML += "</div>";
            
            string ngay = Common.StandardStringjquery(TList_ChuyenMuc[0].NgayCapNhat.ToString("''dd/MM/yyyy, HH:mm 'GMT+7'"));

            //if ("Ch".Equals(ngay.Substring(0, 2)))
                lblNgayCapNhat.Text = ngay;
            //else
            //    lblNgayCapNhat.Text = "Thứ " + ngay;

        }
        else
        {
            strHTML = "<p>Chưa cập nhật dữ liệu</p>";
        }
        
        ltrGioiThieu.Text = strHTML;
    }

    public string GetTieuDe(object Char)
    {
        string s = Char.ToString();
        return Common.ConvertToUnSign(s);
    }
}